let MS = require('./ms.js')
const request = require('./request.js')
const Error = require('./error.js')
const {
    isString,
    isUndefined,
    isNumber,
    isBoolean,
    isArray,
    isObject
} = require('./dataType')

const userScan = class userScan {
    constructor() {}

    findUserScanBySellerId(sellerId) {
        let params = {}
        if(!isUndefined(sellerId) && isString(sellerId)){
            params.sellerId= sellerId
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_SELLER_ID.url,
                MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_SELLER_ID.method, params).then(res => {
                if (res.success) {
                    resolve(res.data)
                } else {
                    reject(res.message)
                }
            }).catch(err => {
                reject(err)
            })
        })
    }

    findUserScanByTargetId(targetId) {
        let params = {
            targetId: targetId
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_TARGET_ID.url,
                MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_TARGET_ID.method, params).then(res => {
                if (res.success) {
                    resolve(res.data)
                } else {
                    reject(res.message)
                }
            }).catch(err => {
                reject(err)
            })
        })
    }

    findUserScanByAppId() {
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_APP_ID.url,
                MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_APP_ID.method, params).then(res => {
                if (res.success) {
                    resolve(res.data)
                } else {
                    reject(res.message)
                }
            }).catch(err => {
                reject(err)
            })
        })
    }

    findUserScanByUserId(userId) {
        let params = {
            userId: userId
        }
        return new Promise((resolve, reject) => {
            request(MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_USER_ID.url,
                MS._config.parameters.USER_SCAN.FIND_USER_SCAN_BY_USER_ID.method, params).then(res => {
                if (res.success) {
                    resolve(res.data)
                } else {
                    reject(res.message)
                }
            }).catch(err => {
                reject(err)
            })
        })
    }
}

module.exports = userScan